import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test_demo/pages/home/components/HotOrderedPage.dart';
import 'package:flutter_test_demo/pages/home/components/ProjectInfo.dart';
import 'package:flutter_test_demo/pages/home/components/orderedPage.dart';
import 'package:flutter_test_demo/pages/search/NetworkPage.dart';
import 'package:flutter_test_demo/static/colors/MyColors.dart';
import 'package:toast/toast.dart';

class MessagePage extends StatefulWidget {
  MessagePage({Key key}) : super(key: key);

  @override
  _MessagePageState createState() => _MessagePageState();
}

class _MessagePageState extends State<MessagePage> {
  TextEditingController _controller = TextEditingController();

  // 已订购
  List onOrder = [
    {"image":"images/book/1.jpg","name":"孩子认真学习", "money": '12.3',"des":"这是一个 '孩子认真学习' 的故事"},
    {"image":"images/book/2.jpg","name":"情商决定一生", "money": '12.3',"des":"这是一个 '情商决定一生' 的故事"},
    {"image":"images/book/3.jpg","name":"道德经", "money": '12.3',"des":"这是一个 '道德经' 的故事"},
    {"image":"images/book/4.jpg","name":"深爱这个城", "money": '12.3',"des":"这是一个 '深爱这个城' 的故事"},
    {"image":"images/book/5.jpg","name":"只因目中无人", "money": '12.3',"des":"这是一个 '只因目中无人' 的故事"},
    {"image":"images/book/6.jpg","name":"人文讲坛目录", "money": '12.3',"des":"这是一个 '人文讲坛目录' 的故事"},
    {"image":"images/book/7.jpg","name":"犯罪心理", "money": '12.3',"des":"这是一个 '犯罪心理' 的故事"},
    {"image":"images/book/8.jpg","name":"养猪学", "money": '12.3',"des":"这是一个 '养猪学' 的故事"},
  ];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _controller.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("订阅"),
        backgroundColor: MyColor.titleColor,
        centerTitle: true,
      ),
      body: ListView(
        children: <Widget>[
          // 搜索框
          Padding(
            padding: EdgeInsets.only(
              left: 12.0,
              top: 20.0,
              right: 12.0,
              bottom: 8.0
            ),
            child: DecoratedBox(
              decoration: BoxDecoration(
                color: Color(0xFFEEEEEE),
                borderRadius: BorderRadius.all(
                  Radius.circular(20.0)
                )
              ),
              child: Row(
                mainAxisAlignment:MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Expanded(
                    child: Padding(
                      padding: EdgeInsets.only(
                        left: 10.0
                      ),
                      child:  TextField(
                        textAlign: TextAlign.start,
                        controller: _controller,
                        decoration:InputDecoration(
                          border: InputBorder.none
                        ),
                        style: TextStyle(
                          color: Colors.black,
                          height: 1.5
                        ),
                      ),
                    ),
                  ),
                  DecoratedBox(
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.all(Radius.circular(20.0)),
                        color: MyColor.titleColor,
                        
                      ),
                      child: Padding(
                        padding: EdgeInsets.symmetric(
                          vertical: 10.0,
                          horizontal: 18.0
                        ),
                        child: InkWell(
                          onTap: (){
                            if(_controller.text == ""){
                              Toast.show("搜索不能为空", context);
                              return null;
                            }
                            Navigator.push(
                              context, 
                              MaterialPageRoute(builder: (context) => NetWorkPage(str: _controller.text),)
                            );
                          },
                          child: Text(
                            "搜索",
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: 15.0
                            ),
                          ),
                        ),
                      )
                  ),
                ],
              ),
            )
          ),
          // 已订阅
          OrderedPage(),

          // 热门推荐
          HotOrderedPage()

        ],
      )
    );
  }
}
